<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>连接状态指示器</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d);
            padding: 20px;
        }

        .container {
            background: rgba(255, 255, 255, 0.9);
            border-radius: 20px;
            padding: 30px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
            max-width: 500px;
            width: 100%;
        }

        h1 {
            text-align: center;
            margin-bottom: 30px;
            color: #333;
            font-weight: 600;
        }

        .connection-status {
            display: flex;
            flex-direction: column;
            gap: 25px;
        }

        .status-item {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 15px;
            background: #f8f9fa;
            border-radius: 12px;
            transition: transform 0.3s ease;
        }

        .status-item:hover {
            transform: translateY(-3px);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
        }

        .status-info {
            display: flex;
            flex-direction: column;
            gap: 5px;
        }

        .status-title {
            font-weight: 600;
            color: #555;
            font-size: 16px;
        }

        .status-desc {
            font-size: 14px;
            color: #777;
        }

        .status-indicator {
            display: flex;
            align-items: center;
        }

        .status-text {
            font-size: 14px;
            color: #FFA71A;
            background-color: rgba(255, 167, 26, 0.1);
            padding: 6px 16px;
            border-radius: 30px;
            display: flex;
            align-items: center;
            position: relative;
        }

        .status-text::before {
            content: "";
            display: inline-block;
            width: 12px;
            height: 12px;
            background-color: #FFA71A;
            border-radius: 50%;
            margin-right: 8px;
            animation: pulse 2s infinite;
            vertical-align: middle;
        }

        /* 不同状态样式 */
        .status-connected .status-text {
            color: #28a745;
            background-color: rgba(40, 167, 69, 0.1);
        }

        .status-connected .status-text::before {
            background-color: #28a745;
            animation: pulse-connected 2s infinite;
        }

        .status-disconnected .status-text {
            color: #dc3545;
            background-color: rgba(220, 53, 69, 0.1);
        }

        .status-disconnected .status-text::before {
            background-color: #dc3545;
            animation: pulse-disconnected 1.5s infinite;
        }

        /* 动画定义 */
        @keyframes pulse {
            0% {
                box-shadow: 0 0 0 0 rgba(255, 167, 26, 0.7);
            }
            70% {
                box-shadow: 0 0 0 6px rgba(255, 167, 26, 0);
            }
            100% {
                box-shadow: 0 0 0 0 rgba(255, 167, 26, 0);
            }
        }

        @keyframes pulse-connected {
            0% {
                box-shadow: 0 0 0 0 rgba(40, 167, 69, 0.7);
            }
            70% {
                box-shadow: 0 0 0 6px rgba(40, 167, 69, 0);
            }
            100% {
                box-shadow: 0 0 0 0 rgba(40, 167, 69, 0);
            }
        }

        @keyframes pulse-disconnected {
            0% {
                box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.7);
            }
            70% {
                box-shadow: 0 0 0 6px rgba(220, 53, 69, 0);
            }
            100% {
                box-shadow: 0 0 0 0 rgba(220, 53, 69, 0);
            }
        }

        .explanation {
            margin-top: 30px;
            padding: 20px;
            background: #f8f9fa;
            border-radius: 12px;
        }

        .explanation h2 {
            margin-bottom: 15px;
            color: #333;
            font-size: 20px;
        }

        .explanation p {
            margin-bottom: 10px;
            color: #555;
            line-height: 1.6;
        }

        .code {
            background: #2d2d2d;
            color: #f8f9fa;
            padding: 15px;
            border-radius: 8px;
            font-family: Consolas, Monaco, 'Andale Mono', monospace;
            overflow-x: auto;
            margin-top: 15px;
        }
    </style>
</head>
<body>
<div class="container">
    <h1>连接状态指示器</h1>

    <div class="connection-status">
        <div class="status-item">
            <div class="status-info">
                <div class="status-title">设备A</div>
                <div class="status-desc">会议室智能终端</div>
            </div>
            <div class="status-indicator">
                <div class="status-text">连接中</div>
            </div>
        </div>

        <div class="status-item status-connected">
            <div class="status-info">
                <div class="status-title">设备B</div>
                <div class="status-desc">投影仪</div>
            </div>
            <div class="status-indicator">
                <div class="status-text">已连接</div>
            </div>
        </div>

        <div class="status-item status-disconnected">
            <div class="status-info">
                <div class="status-title">设备C</div>
                <div class="status-desc">音响系统</div>
            </div>
            <div class="status-indicator">
                <div class="status-text">已断开</div>
            </div>
        </div>
    </div>

    <div class="explanation">
        <h2>实现圆点与文字垂直居中的方法</h2>
        <p>关键CSS代码：</p>
        <div class="code">
            .status-text {
            display: flex;          /* 使用flex布局 */
            align-items: center;    /* 垂直居中子元素 */
            /* 其他样式 */
            }

            .status-text::before {
            vertical-align: middle; /* 额外的垂直居中保障 */
            /* 其他样式 */
            }
        </div>
        <p>通过将.status-text设置为flex布局，并使用align-items: center，可以确保其中的伪元素(圆点)和文字内容垂直居中。</p>
    </div>
</div>

<script>
  // 简单实现状态切换效果
  document.querySelectorAll('.status-item').forEach(item => {
    item.addEventListener('click', () => {
      // 移除所有状态类
      item.classList.remove('status-connected', 'status-disconnected');

      // 循环切换状态
      if (!item.classList.contains('status-connected') &&
        !item.classList.contains('status-disconnected')) {
        item.classList.add('status-connected');
        item.querySelector('.status-text').textContent = '已连接';
      } else if (item.classList.contains('status-connected')) {
        item.classList.remove('status-connected');
        item.classList.add('status-disconnected');
        item.querySelector('.status-text').textContent = '已断开';
      } else {
        item.classList.remove('status-disconnected');
        item.querySelector('.status-text').textContent = '连接中';
      }
    });
  });
</script>
</body>
</html>
